from typing import Optional

from sqlalchemy import BigInteger, DateTime, Integer, PrimaryKeyConstraint, String, func, DECIMAL
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import datetime

from config.database import Base
from utils.uuid import UUID


class CmsOrder(Base):
    __tablename__ = 'cms_order'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='_copy_1'),
        {'comment': '用车订单'}
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, default=int(UUID().uuid()))
    state: Mapped[int] = mapped_column(Integer,
                                       comment='状态（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）')
    create_time: Mapped[datetime.datetime] = mapped_column(DateTime, comment='创建时间', server_default=func.now())
    order_id: Mapped[Optional[str]] = mapped_column(String(32), comment='单号')
    user_id: Mapped[Optional[str]] = mapped_column(String(32), comment='用车人')
    phone: Mapped[Optional[str]] = mapped_column(String(32), comment='联系电话')
    department_id: Mapped[Optional[str]] = mapped_column(String(32), comment='用车部门')
    use_user_id: Mapped[Optional[str]] = mapped_column(String(32), comment="用车人id")
    rading_count: Mapped[Optional[int]] = mapped_column(Integer, comment='乘坐人数')
    car_count: Mapped[Optional[int]] = mapped_column(Integer, comment="用车数量")
    expected_mileage: Mapped[Optional[float]] = mapped_column(DECIMAL(10, 2), comment="预计里程")
    start: Mapped[Optional[str]] = mapped_column(String(255), comment='出发地（可以有多个）')
    destination: Mapped[Optional[str]] = mapped_column(String(255), comment='目的地（可以有多个）')
    plan_begin_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='预计出车时间')
    plan_end_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='预计回车时间')
    use_car_type: Mapped[Optional[str]] = mapped_column(String(32), comment='用车类型（个人用车，领导用车，客户用车）')
    dispatch_type: Mapped[Optional[str]] = mapped_column(String(32), comment='调度类型（普通调度，应急调度）')
    remark: Mapped[Optional[str]] = mapped_column(String(255), comment='用车备注')
    create_by: Mapped[Optional[str]] = mapped_column(String(32), comment='创建人-申请人')
    update_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='修改时间',
                                                                     server_default=func.now(), onupdate=func.now())
    update_by: Mapped[Optional[str]] = mapped_column(String(32), comment='修改人')
    car_model: Mapped[Optional[str]] = mapped_column(String(32), comment='车型')
    car_type: Mapped[Optional[str]] = mapped_column(String(32), comment='车辆类型')
